﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using NewstorePlateformeDAO;

namespace NewstorePlateformeMobileApp.Controllers
{
    public class ConnexionController : Controller
    {
        //
        // GET: /Connexion/

        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Validation(string login, string password)
        {
            try
            {
                bool exist = Utilisateur.Exist(login, password);

                if (exist)
                {
                    SessionHelper.SetSession(SessionHelper.sessionVariables.iUTILIS_ID, Utilisateur.GetId(login, password));
                    return Json(new string[2] { "1", "Valide" });
                }
                else
                    return Json(new string[2] { "0", "Utilisateur inexistant" });
            }
            catch (Exception ex)
            {
                return Json(new string[2] { "-1", ex.Message });
            }
        }

    }
}
